home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_exmh.idb / usr / freeware / lib / exmh-2.5 / busy.tcl.z / busy.tcl
Text File  |  2002-07-08  |  6KB  |  214 lines

  1. # busy.tcl
  2. #
  3. # Busy feedback.
  4. #
  5. # Copyright (c) 1993 Xerox Corporation.
  6. # Use and copying of this software and preparation of derivative works based
  7. # upon this software are permitted. Any distribution of this software or
  8. # derivative works must comply with all applicable United States export
  9. # control laws. This software is made available AS IS, and Xerox Corporation
  10. # makes no warranty about the software, its performance or its conformity to
  11. # any specification.
  12.  
  13. proc Busy_Init {} {
  14.     global busy exmh
  15.  
  16.     Preferences_Add "Busy Indicator" \
  17. "These items affect how exmh indicates it is busy." \
  18.     [list \
  19.         {busy(style) busyStyle {CHOICE cursor icon cursorAll none} {How to indicate busy}
  20. "icon - show a bitmap in the faces display.
  21. cursor - change the cursor to a busy indicator.
  22. cursorAll - Like cursor, but hits all widgets and takes longer.
  23. none - do nothing."} \
  24.     [list busy(cursor) busyCursor watch {Cursor for busy indicator} \
  25. "This is a TK specification for a cursor.  You can use a standard
  26. X cursor, like \"watch\", or provide your own bitmaps and mask
  27. with \"@filename\".  You can optionally provide foreground and
  28. background colors. (See Tk_GetCursor for complete details).
  29. A final twist is that relative pathnames are munged to be
  30. absolute pathnames under $exmh(library)
  31. Examples include:
  32.     watch        - standard watch
  33.     watch blue        - a clear and blue watch
  34.     watch blue white    - a white and blue watch
  35.     @timer.bitmap black     - 16x16 timer/watch (need fg color!)
  36.     @hourglass1.bitmap black    - Standard wish hourglass
  37.     @hourglass2.bitmap blue    - Large 32x32 hourglass, in blue
  38.     @hourglass2.bitmap hourglass2.mask red black - (need two colors!)
  39.     @/usr/foo/exmh/bar.mask /usr/foo/exmh/bar.bitmap black yellow
  40. "] \
  41.     [list busy(bitmap) busyBitmap @hourglass2.bitmap {Bitmap for busy indicator} \
  42. "This is a TK specification for a bitmap.  There are only a few
  43. boring built-in bitmaps, so mostly you specify these with the
  44. @pathname syntax.  A relative pathname is munged to be an
  45. absolute pathname under $exmh(library)
  46. Examples include:
  47.     @hourglass1.bitmap        - Standard wish hourglass
  48.     @hourglass1.bitmap blue    - Blue wish hourglass
  49.     @/usr/foo/exmh/bar.bitmap
  50. "] \
  51.     ]
  52.     set busy(color) black
  53.     trace variable busy(cursor) w BusyFixupCursor
  54.     BusyFixupCursor
  55.  
  56.     trace variable busy(bitmap) w BusyFixupBitmap
  57.     BusyFixupBitmap
  58.  
  59. }
  60. proc BusyFixupCursor { args } {
  61.     global busy exmh
  62.     # busy(cursor) could be
  63.     # @foo.cursor bar.cursor color color
  64.     # Here we insert the exmh library
  65.     switch -regexp $busy(cursor) {
  66.     {^@[^/]} {
  67.         regsub @(.*) $busy(cursor) $exmh(library)/\\1 newfile
  68.         if ![file exists [lindex $newfile 0]] {
  69.         Exmh_Status "Invalid file [lindex $newfile 0]"
  70.         return
  71.         }
  72.         if {[llength $newfile] > 2} {
  73.         regsub {([^ ]*) (.*)} $newfile "\\1 $exmh(library)/\\2" newfile
  74.         }
  75.         set busy(Xcursor) @$newfile
  76.     }
  77.      .* {
  78.         set busy(Xcursor) $busy(cursor)
  79.     }
  80.     }
  81. }
  82. proc BusyFixupBitmap { args } {
  83.     global busy exmh
  84.     # busy(bitmap) could be
  85.     # @foo.bitmap bar.bitmap color color
  86.     # Here we insert the exmh library
  87.     switch -regexp $busy(bitmap) {
  88.     {^@[^/]} {
  89.         regsub @(.*) $busy(bitmap) $exmh(library)/\\1 newfile
  90.         set color [lindex $newfile 1]
  91.         set newfile [lindex $newfile 0]
  92.         if [file exists $newfile] {
  93.         set busy(Xbitmap) @$newfile
  94.         } else {
  95.         Exmh_Status "Invalid file $newfile"
  96.         return
  97.         }
  98.     }
  99.      .* {
  100.         set busy(Xbitmap) [lindex $busy(bitmap) 0]
  101.         set color [lindex $busy(bitmap) 1]
  102.     }
  103.     }
  104.     if {[string length $color]} {
  105.     set busy(color) $color
  106.     } else {
  107.     set busy(color) black
  108.     }
  109. }
  110. proc busy { args } {
  111.     global busy
  112.     switch $busy(style) {
  113.     icon        {busyIcon $args}
  114.     cursorAll    {busyCursor $args}
  115.     cursor        {busyCursorHack $args}
  116.     default        {eval $args}
  117.     }
  118. }
  119. proc busyIcon { cmd } {
  120.     global errorInfo busy
  121.  
  122.     set parent [Face_BusyParent]
  123.     # Recreate the widget every time so that display works properly
  124.     if [catch {
  125.     set label \
  126.         [label $parent.busy -foreground $busy(color) -bitmap $busy(Xbitmap)]
  127.     Face_BusyPlace $label
  128.     } err] {
  129.     Exmh_Debug $err
  130.     }
  131.  
  132.     set error [catch {uplevel #0 $cmd} result]
  133.     set ei $errorInfo
  134.  
  135.     if [info exists label] {
  136.     Face_BusyDestroy $label
  137.     }
  138.  
  139.     if $error {
  140.     error $result $ei
  141.     } else {
  142.     return $result
  143.     }
  144.  
  145. }
  146. proc busyCursorInner { cmd widgets } {
  147.     global errorInfo busy
  148.     foreach w $widgets {
  149.     catch {[lindex $w 0] config -cursor $busy(Xcursor)}
  150.     }
  151.     update idletasks
  152.  
  153.     set error [catch {uplevel #0 $cmd} result]
  154.     set ei $errorInfo
  155.  
  156.     foreach w $widgets {
  157.     catch {[lindex $w 0] config -cursor [lindex $w 1]}
  158.     }
  159.     if $error {
  160.     error $result $ei
  161.     } else {
  162.     return $result
  163.     }
  164. }
  165. proc busyCursorHack {cmd} {
  166.     set widgets {}
  167.     catch {
  168.     #Fdisp_Busy
  169.     global fdisp
  170.     foreach can {canvas cache} {
  171.         if [info exists fdisp($can)] {
  172.         set w $fdisp($can)
  173.         set cursor [lindex [$w config -cursor] 4]
  174.         lappend widgets [list $w $cursor]
  175.         }
  176.     }
  177.     #Exwin_Busy
  178.     global exwin
  179.     foreach w [list $exwin(mtext) $exwin(ftext)] {
  180.         set cursor [lindex [$w config -cursor] 4]
  181.         lappend widgets [list $w $cursor]
  182.     }
  183.     #Sedit_Busy
  184.     global sedit
  185.     foreach w $sedit(allids) {
  186.         set cursor [lindex [$w config -cursor] 4]
  187.         lappend widgets [list $w $cursor]
  188.     }
  189.     #Label_Busy
  190.     global label
  191.     foreach w [list $label(main) $label(folder) $label(message) $exwin(status)] {
  192.         set cursor [lindex [$w config -cursor] 4]
  193.         lappend widgets [list $w $cursor]
  194.     }
  195.     }
  196.     return [busyCursorInner $cmd $widgets]
  197. }
  198. proc busyCursor {cmd} {
  199.     set widgets {.app .root}
  200.     set list [winfo children .]
  201.     while {$list != ""} {
  202.     set next {}
  203.     foreach w $list {
  204.         set cursor [lindex [$w config -cursor] 4]
  205.         lappend widgets [list $w $cursor]
  206.         set next [concat $next [winfo children $w]]
  207.     }
  208.     set list $next
  209.     }
  210.     return [busyCursorInner $cmd $widgets]
  211. }
  212.  
  213.